<script type="text/javascript" src="../wp-content/plugins/stSocialMediaToolbox/Toolboxes/stContestToolbox/scripts/backend/jquery-ui-1.8.7.custom.min.js"></script>
<script type="text/javascript" >
    jQuery(document).ready(function() {
        jQuery(".galleryVideo a[rel^='prettyPhoto']").prettyPhoto({
            theme:'facebook',
            keyboard_shortcuts: false
        });
        stContestToolbox.sortColumn();
        stContestToolbox.shortAction();
        
    });
</script>
<?php 

function contest_format_date($input) {
    $d = substr($input, 0, 16);    
    $d = str_replace("-",".", $d);
    
    $darrs = explode(" ", $d);
    $date = $darrs[0];
    $time = $darrs[1];
    $dateArrs = explode(".", $date);
    $dateStr = $dateArrs[2] . "." . $dateArrs[1] . "." . $dateArrs[0];
    return $dateStr . " " . $time;
}

?>
<div style="float:right;font-size:20px;margin-right:50px;margin-top:-20px;">Active contest: <?php if($activeContest){ echo $activeContest->name;} else { echo "None"; } ?></div>
<div class="w100p bgl">
    <div class="w100p bgr">
        <div class="inner_container">
            <table class="widefat galleryVideo" cellspacing="0">
                <thead>
                    <tr>
                        <?php print_column_headers('stcontest_st_contestlist'); ?>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        if (count($results) > 0) {
                            $tr_class = "";
                            
                            foreach ($results as $result) {  
                                $activeText = " | Activate";
                                $newStatus = "1";
                                $colorStr = "#FFFFFF";
                                
                                if($result->is_active == 1) {
                                    $activeText = " | Deactivate";
                                    $newStatus = "0";
                                    $colorStr = "#ECEBA3";
                                }
                               echo "<tr style='background-color:{$colorStr}' id='$result->contest_id' $tr_class>"   
                                . "<td> {$result->contest_id}  </td>"   
                                . "<td ><div class='pos_rel'>" . stContestToolboxFunctions::limitWords($result->name, 5)
                                . "<div class=\"row-actions short_action\">"
                                . "<a href='?page=stContestToolbox&action=contest_edit&id={$result->contest_id}'>Edit</a>"                                                                
                                . "<span class='edit' action='' short_action='active' id='{$result->contest_id}_{$newStatus}'>{$activeText} </span>"
                                . " | <span class='trash' short_action='delete' id='$result->contest_id' confirm='All votes and user data for this contest will be deleted.<br/>Are you sure you want to proceed?'>Trash </span>"                                
                                . "</div></div>"
                                . "</td>"
//                                . "<td> {$result->title}  </td>"                                
//                                . "<td>" . stContestToolboxFunctions::limitWords($result->description, 15) . "</td>"
                                . "<td>" . contest_format_date($result->created_date) . "</td>"
                                . "<td>" . contest_format_date($result->start_date) . "</td>"
                                . "<td>" . contest_format_date($result->end_date) . "</td>";                                                                 
                                echo "</tr>"
                                ;
                            }
                        }
                    ?>
                    </tbody>
                </table>
                <div class="page_d">
                <?php echo $pagination ?>
                <div class="cl"></div>
            </div>

        </div>
    </div>
</div>